<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>系统选项卡菜单强化</title>
		<!--导入jQuery核心类库-->
		<script src="../js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
		<!--导入jQuery Easy UI核心类库-->
		<script src="../js/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
		<!--导入国际化信息文件-->
		<script src="../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
		<!--导入默认主题CSS文件-->
		<link rel="stylesheet" type="text/css" href="../js/easyui/themes/default/easyui.css" />
		<!--导入图标CSS文件-->
		<link rel="stylesheet" type="text/css" href="../js/easyui/themes/icon.css" />
		<!--引入Ztree核心类库-->
		<script src="../js/ztree/jquery.ztree.all-3.5.js" type="text/javascript" charset="utf-8"></script>
		<!--引入Ztree的CSS样式-->
		<link rel="stylesheet" type="text/css" href="../js/ztree/zTreeStyle.css" />

		<!--jQueyr绑定事件操作-->
		<script type="text/javascript">
			//页面加载完成后执行
			$(function() {
				//1.进行Ztree的设置
				var setting = {
					data: {
						simpleData: {
							enable: true //启用简单json数据格式(默认是不支持简单json格式的)
						}
					},
					callback: {
						onClick: function(event, treeId, treeNode, clickFlag) {
							var content = '<div style="width:100%;height:100%;overflow:hidden;">' +
								'<iframe src="' + treeNode.page +
								'"scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></div>';

							//判断，没有page树形菜单，不打开选项卡
							if(treeNode.page != undefined && treeNode.page != "") {
								//如果选项卡已经打开，则选中
								if($("#mytabs").tabs('exists', treeNode.name)) {
									//选中选项卡
									$("#mytabs").tabs('select', treeNode.name);
								} else {
									//如果没有打开，则添加选项卡
									$("#mytabs").tabs('add', {
										title: treeNode.name,
										content: content,
										closable: true
									});
								}
							}
						}
					}
				};

				//2.编写树形菜单数据
				var zNodes = [{
						id: 1,
						pId: 0,
						name: "父结点一"
					},
					{
						id: 2,
						pId: 0,
						name: "父结点二"
					},
					{
						id: 11,
						pId: 1,
						name: "子结点一"
					},
					{
						id: 12,
						pId: 1,
						name: "子结点二"
					},
					{
						id: 21,
						pId: 2,
						name: "子结点三"
					},
					{
						id: 22,
						pId: 2,
						name: "子结点四"
					},
					//1.添加自定义属性page
					//2.为Ztree的每个树形结点添加点击事件
					{
						id: 13,
						pId: 1,
						name: "百度一下",
						page: "http://www.baidu.com"
					},
					{
						id: 23,
						pId: 2,
						name: "hao123",
						page: "http://www.hao123.com"
					}
				];

				//3.生成树形菜单
				$.fn.zTree.init($("#basemenu"), setting, zNodes);
				
				//对选项卡注册右键事件
				$("#mytabs").tabs({
					onContextMenu:function(e,title,index){
						//阻止默认菜单显示
						e.preventDefault();
						
						//显示自定义右键菜单
						$("#mm").menu('show',{
							left:e.pageX,
							top:e.pageY
						});
					}
				});
			})
			
			//对自定义菜单选项绑定点击事件
			$("#dq").click(function(){
				//
			})
		</script>
	</head>
	<!--页面布局可以基于body和div-->

	<body class="easyui-layout">

		<div data-options="region:'north',title:'North Title',split:true" style="height:100px;"></div>

		<div data-options="region:'south',title:'South Title',split:true" style="height:100px;"></div>

		<div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true" style="width:100px;"></div>

		<div data-options="region:'west',title:'West',split:true" style="width:150px;">

			<div class="easyui-accordion" data-options="fit:true" >
				<div title="基础菜单" style="overflow:auto;">
					<!--通过Ztree插件制作树形菜单-->
					<ul id="basemenu" class="ztree">
					</ul>
				</div>

				<div title="折叠菜单二" data-options="iconCls:'icon-reload',selected:true" style="padding:10px;">

					content2

				</div>

				<div title="折叠菜单三">

					content3

				</div>
			</div>

		</div>

		<div data-options="region:'center'" class="easyui-tabs" id="mytabs">

			<div title="Tab1" data-options="iconCls:'icon-reload',closable:true" style="overflow:auto;padding:20px;display:none;">tab1 </div>

			<div title="Tab2" data-options="iconCls:'icon-reload',closable:true" style="overflow:auto;padding:20px;display:none;">tab2 </div>

			<div title="Tab3" data-options="iconCls:'icon-reload',closable:true" style="overflow:auto;padding:20px;display:none;">tab3 </div>

		</div>
		
		<!--在所有布局之外设计右键菜单，并隐藏。-->
		<div id="mm" class="easyui-menu" style="width:120px">
			<div id="dq">关闭当前窗口</div>		
			<div id="qt">关闭其他窗口</div>
			<div class="menu-sep"></div><!--分割线-->
			<div data-options="iconCls:'icon-cancel'" id="sy">关闭全部窗口</div>
		</div>
		<!--如果是二级菜单，形式如下
			<div>
				<span>一级选项1</span>
				<div style="width:150px">
					<div>子选项1</div>
					<div>子选项2</div>
					<div>子选项3</div>
				</div>
			</div>
			<div>一级选项2</div>
			<div>一级选项3</div>
			<div>一级选项4</div>
		-->
	</body>

</html>